package java流相关;

import java.io.*;

/**
 * @author coderFu
 * @create 2022/3/4
 * 字符流
 * 为什么会有字符流: 用于更好的处理文本文件
 *
 * 文件字符输入流FileReader， 文件字符输出流FileWriter 这梁总流联合
 * 起来完成最基本的字符操作。
 */
public class ByteStream {

    public static void main(String[] args) throws IOException {
        File srcFile = new File("china.txt");
        File desFile = new File("success.txt");
        Writer writer = new FileWriter(srcFile,false);

        writer.write("快来学java吧，一起加油！");
        writer.write("\n");
        writer.write("我在这里等你的到来");
        writer.flush();
        writer.close();

        // 读出文件中的内容
        Reader reader = new FileReader(srcFile);
        Writer writer1 = new FileWriter(desFile);
        char[] buffer = new char[1024];
         int  len;
         while ((len = reader.read(buffer)) != -1){
             writer1.write(buffer,0,len);
             String s = new String(buffer,0,len);
             System.out.println(s);
         }
         reader.close();
         writer1.close();
    }

}
